<template>
  <div>
    <!-- 搜索区域 -->
    <el-row>
      <el-form :inline="true" :model="queryInfo">
        <el-form-item>
          <el-button type="primary" @click="repairs">批量恢复</el-button>
          <el-button type="danger" @click="delBacth">批量删除</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <!-- 表格区域 -->
    <el-table
      :data="dataList1"
      border
      style="width: 100%"
      stripe="true"
      :row-style="{height: '50px'}"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column align="center" prop="id" label="ID"></el-table-column>
      <el-table-column align="center" prop="aid" label="文章id"></el-table-column>
      <el-table-column align="center" prop="article.articleName" label="文章标题"></el-table-column>
      <el-table-column align="center" prop="delTime" label="删除时间"></el-table-column>
      <el-table-column align="center" label="操作">
        <template v-slot="scope">
          <el-button type="primary" plain @click="repair(scope.row.id)">恢复</el-button>
          <el-button type="danger" plain @click="del(scope.row.id)">永久删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div id="footer">
      <el-pagination
        background
        :default-page-size="5"
        :page-sizes="[5, 8, 10]"
        :size="size"
        :disabled="disabled"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @current-change="changePageNum"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>
      
  <script setup >
import { ref, onMounted, getCurrentInstance } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";

import { SortUp, Plus } from "@element-plus/icons-vue";
import ArticleCategory from "./ArticleCategory.vue";

const currentInstance = getCurrentInstance();
const { $http } = currentInstance.appContext.config.globalProperties;
const dataList1 = ref([]);

const total = ref();
let ids = ref([]);

// 定义查询对象 用来获取表单数据
let queryInfo = ref({
  title: "",
  fmCategoryId: "",
  pageNum: 1,
  pageSize: 5
});

//挂载后执行请求community数据
onMounted(() => {
  getdata();
});
//数据请求方法
function getdata() {
  $http({
    method: "get",
    url: "http://localhost:8081/sfzy/recycleBin/page",
    params: queryInfo.value
  }).then(res => {
    console.log(res.data.data);
    dataList1.value = res.data.data.list;
    total.value = res.data.data.total;
  });
}

/*---------------- 删除/批量删除 部分------------------------*/
//删除
function del(id) {
  $http({
    method: "delete",
    url: "http://localhost:8081/sfzy/recycleBin/" + id
  }).then(res => {
    if (res.data.code == 200) {
      ElMessage.success("删除成功！");
      getdata();
    } else {
      ElMessage.error("删除失败！");
    }
  });
}
// //删除
// function del() {
//         $http({
//           method: "delete",
//           url: "http://localhost:8081/sfzy/recycleBin/repairs?ids=" + ids.value
//         }).then(res => {
//           if (res.data.code == 200) {
//             ElMessage.success("恢复成功！");
//             getdata();
//           } else {
//             ElMessage.error("恢复失败！");
//           }
//         });
// }

/*---------------- 恢复/批量恢复 部分------------------------*/
//恢复
function repair(id) {
  $http({
    method: "delete",
    url: "http://localhost:8081/sfzy/recycleBin/repair/" + id
  }).then(res => {
    if (res.data.code == 200) {
      ElMessage.success("恢复成功！");
      getdata();
    } else {
      ElMessage.error("恢复失败！");
    }
  });
}
//批量
function repairs() {
  if (ids.value != null && ids.value != "") {
    ElMessageBox.confirm("确认要恢复数据吗?", "Warning", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning"
    })
      .then(() => {
        $http({
          method: "delete",
          url: "http://localhost:8081/sfzy/recycleBin/repairs?ids=" + ids.value
        }).then(res => {
          if (res.data.code == 200) {
            ElMessage.success("恢复成功！");
            getdata();
          } else {
            ElMessage.error("恢复失败！");
          }
        });
      })
      .catch(() => {
        ElMessage({
          type: "info",
          message: "取消恢复！"
        });
      });
  }
}

//pageNum
function changePageNum(num) {
  // 修改页码
  queryInfo.value.pageNum = num;
  //再次查询
  getdata();
}

//pageSize
function handleSizeChange(size) {
  queryInfo.value.pageSize = size;
  getdata();
}
</script>
      
  <style scoped>
:deep(.ql-container) {
  min-height: 200px;
  min-width: 468px;
  max-width: 468px;
  max-height: 200px;
}

#button {
  margin-left: 250px;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-pagination {
  margin-left: 200px;
}

#footer {
  height: 80px;
  margin: 40px;
}
</style>